package com.example.demo.controller;

import com.example.demo.anno.Log;
import com.example.demo.common.Result;
import com.example.demo.pojo.Company_Student;
import com.example.demo.pojo.RecruitInfo;
import com.example.demo.pojo.Student;
import com.example.demo.pojo.YaoQing;
import com.example.demo.service.RecruitInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachePut;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//这里是springCache和redis
@RestController
public class RecruitInfoController {
    @Autowired
    private CacheManager cacheManager;
    @Autowired
    private RecruitInfoService recruitInfoService;

    //springcache,缓存,所有公司的信息//这个key只能是数字???
    @Log
//    @CachePut(value = "recruitCache",key = "123")//value是缓存名,一个value可包含多个key ,cacheput将方法返回值放入缓存,key="#result"是方法的返回值,="#user.id"
    @GetMapping("/recruitInfo")
    public Result selectUser(){
        List<RecruitInfo> List = recruitInfoService.selectRecruitInfo();
        return Result.success(List);
    }

    //根据?公司?账号 获取学生投递的公司简历
    @Log
    @GetMapping("/recruitInfo/{account}")
    public Result getByAccount(@PathVariable String account){
        List<RecruitInfo> List = recruitInfoService.getByAccount(account);
        return Result.success(List);
    }
    //根据公司账号 获取学生投递过来的'账号' 是company_student表
    @Log
    @GetMapping("/recruit/{accountCm}")
    public Result getAccountByAccountCm(@PathVariable String accountCm){
        List<Company_Student> list = recruitInfoService.getAccountByAccountCm(accountCm);
        return Result.success(list);
    }

    @Log
    @PostMapping("/recruitInfoSave")
    public Result save(@RequestBody RecruitInfo recruitInfo){
        recruitInfoService.save(recruitInfo);
        return Result.success();
    }

    @Log
    @PutMapping("/recruitUpdate")
    public Result update(@RequestBody RecruitInfo recruitInfo){
        recruitInfoService.update(recruitInfo);
        return Result.success();
    }

    @Log
    @PostMapping("/yaoQing")
    public Result yaoQing(@RequestBody YaoQing yaoQing){
        recruitInfoService.yaoQing(yaoQing);
        return Result.success();
    }

    //公司同意学生来面试
    @Log
    @PutMapping("/Company_StudentUpdate/{accountCm}/{accountStu}")//路径变量
    public Result updateCompany_Student(@RequestBody Company_Student companyStudent,@PathVariable String accountCm,@PathVariable String accountStu){
        companyStudent.setAccountCm(accountCm);
        companyStudent.setAccountStu(accountStu);
        System.out.println(companyStudent.getAccountCm()+""+companyStudent.getAccountStu());
        recruitInfoService.updateCompany_Student(companyStudent);
        return Result.success();
    }

    //管理员审核信息通过
    @Log
    @PutMapping("/recruitUpdate1/{accountCm}")
    public Result recruitUpdate(@PathVariable String accountCm){
        recruitInfoService.recruitUpdate(accountCm);
        return Result.success();
    }



}
